package cn.itcast.spring.demo1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.springframework.http.MediaTypeEditor;

public class CustomerProxy implements InvocationHandler{
	private CustomerService customerService;
	
	
	public CustomerProxy(CustomerService customerService){
		this.customerService = customerService;
	}
	
	public CustomerService createCustomerServiceProxy(){
		CustomerService newProxyInstance = (CustomerService) Proxy.newProxyInstance(customerService.getClass().getClassLoader(), customerService.getClass().getInterfaces(), this);
		return newProxyInstance;
		
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		if(method.getName().equals("eat")){
			System.out.println("吃饭之前要洗手");
			return 	method.invoke(customerService, args);
		}
		return 	method.invoke(customerService, args);
	}
	
	
	
	
	
	

}
